  //定义食物的构造函数  自调用函数 --自执行函数
  (function() {
      //添加一个 储存 食物的数组
      var arrFood = []

      function Food(x, y, weight, height, bgcolor) {
          this.x = x;
          this.y = y;
          this.weight = weight || '20';
          this.height = height || '20';
          this.bgcolor = bgcolor || 'green'
      }
      //初始化创建在 地图中
      Food.prototype.init = function(map) {
          remove()
          var div = document.createElement('div')
          div.style.position = 'absolute'
          this.x = (parseInt(Math.random() * (map.offsetWidth / this.weight)) * this.weight)
          this.y = (parseInt(Math.random() * (map.offsetHeight / this.height)) * this.height)
          div.style.left = this.x + 'px'
          div.style.top = this.y + 'px'
          div.style.width = this.weight + 'px'
          div.style.height = this.height + 'px'
          div.style.backgroundColor = this.bgcolor
          map.appendChild(div)
              //把这个元素存入数组
          arrFood.push(div)
      }

      //清除食物，保证页面只有1个食物。或者小蛇吃了后，页面食物被清除
      function remove() {
          if (arrFood.length != []) {
              arrFood[0].parentNode.removeChild(arrFood[0])
              arrFood = []
          }
      }
      window.Food = Food;
  })();